#! /usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) JoinQuant Development Team
# Author: Huayong Kuang <kuanghuayong@joinquant.com>

from types import ModuleType

def fetch_obj():
    module = ModuleType(b'user_code')
    module.__file__ = "user_code.py"

    with open("outer_code2.py") as f:
        source = f.read()

    code = compile(source,
                   module.__file__,
                   'exec',
                   dont_inherit=True)
    exec(code, module.__dict__)

    print(module)

    obj = getattr(module, "Test")()

    return obj


def main():
    # obj = fetch_obj()
    module = ModuleType(b'user_code')
    module.__file__ = "user_code.py"

    with open("outer_code2.py") as f:
        source = f.read()

    code = compile(source,
                   module.__file__,
                   'exec',
                   dont_inherit=True)
    exec(code, module.__dict__)

    print(module)

    obj = getattr(module, "Test")()
    print(obj)

    from calc import calc_test
    print(calc_test(obj))


if __name__ == "__main__":
    main()
